package com.beone.smart.userCenter.controller;

import com.beone.smart.userCenter.model.entity.UserInfoDO;
import com.beone.smart.userCenter.model.result.ResultEntity;
import com.beone.smart.userCenter.model.result.ResultTool;
import com.beone.smart.userCenter.service.intf.UserInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * @Date: 2019/8/6
 * @Author: yangjie
 **/
@Api(tags = "用户API")
@RestController
@RequestMapping(value = "/user_info")
@Slf4j
public class UserInfoController {
    @Autowired
    private UserInfoService userInfoService;

    @ApiOperation(value = "用户注册", notes = "现在是简单注册")
    @GetMapping(value = "/test")
    public ResultEntity test(HttpServletRequest request
    ) {
        String token = request.getHeader("token");
        log.info("取出的token是{}", token);
        UserInfoDO userInfoDO = new UserInfoDO();
        return ResultTool.ok(userInfoDO);
    }

    @ApiOperation(value = "用户注册", notes = "现在是简单注册")
    @PostMapping(value = "/register")
    public ResultEntity createUser(
            @ApiParam(name = "user_name", value = "用户名", required = true) @RequestParam String user_name,
            @ApiParam(name = "password", value = "密码", required = true) @RequestParam String password,
            @ApiParam(name = "email", value = "邮箱", required = true) @RequestParam String email) {
        UserInfoDO userInfoDO = new UserInfoDO();
        return ResultTool.ok(userInfoDO);
    }

    @ApiOperation(value = "用户登录")
    @PostMapping(value = "/login")
    public ResultEntity login(
            @ApiParam(name = "user_name", value = "用户名", required = true) @RequestParam String user_name,
            @ApiParam(name = "password", value = "密码", required = true) @RequestParam String password
    ) {
        UserInfoDO userInfoDO = new UserInfoDO();
        return ResultTool.ok(userInfoDO);
    }

    @ApiOperation(value = "刷新token")
    @PostMapping(value = "/refresh_token")
    public ResultEntity refresh_token(
            @ApiParam(name = "user_name", value = "用户名", required = true) @RequestParam String user_name,
            @ApiParam(name = "token", value = "token", required = true) @RequestParam String token
    ) {
        UserInfoDO userInfoDO = new UserInfoDO();
        return ResultTool.ok(userInfoDO);
    }
}
